/**
 * Created by huachuan on 2016/1/11.
 */
angular.module('meattendservice',[])
  //我关注的Service
  .factory('MeAttend', function($resource,$rootScope,ENV) {

    //访问的地址
    var APIUrl = ENV.api;
    //接收返回值
    var meattentionListJson,memberListJson,focusFriendMsgJson;
    //获取$resource
    var getAttentionListResource = $resource(APIUrl + 'meAttention/getAttentionList.do');
    var findMemberListByKeyResource = $resource(APIUrl+'meAttention/searchMemberList.do');
    var focusFriendResource = $resource(APIUrl+'meAttention/focusFriend.do');

    return {
       //关注会员
      focusFriend:function(memberId,toAttendMemberId){
        focusFriendResource.save({
          member_id:memberId,
          to_attend_member_id:toAttendMemberId
        },function(response){
          focusFriendMsgJson = response;
          console.log(focusFriendMsgJson);
          $rootScope.$broadcast('MeAttend.focusFriendUpdated');
        });
      },
      getFocusFriendMsgJson:function(){
        return focusFriendMsgJson;
      },
      //根据关键字搜索会员列表
      findMemberListByKey:function(searchKey,memberId){
        findMemberListByKeyResource.save({
          searchKey:searchKey,
          member_id:memberId
        },function(response){
          memberListJson = response;
          $rootScope.$broadcast('MeAttend.memberListByKeyUpdated');
        });
      },
      getMemberListJson:function(){
        return memberListJson;
      },
        //获取到我的关注和关注我的列表
        getMeAttentionList:function(memberId){
          getAttentionListResource.save({
            member_id:memberId
          },function(response){
            meattentionListJson = response;
            $rootScope.$broadcast('MeAttend.meAttentionListUpdated');
          });
        },
        getMeAttentionListJson:function(){
          return meattentionListJson;
        }
    }
  })
